<?php
declare (strict_types=1);

namespace app\mall\service\address;

use app\common\service\BaseService;
use app\mall\logic\address\Address as AddressLogic;
use think\annotation\Inject;
use think\facade\Request;
use think\Response;

/**
 * 商品管理
 */
class Address extends BaseService
{

    /**
     * @Inject()
     * @var AddressLogic
     */
    protected $addr;

    /**
     * 新增地址
     * Author: 亓官雨树 <lucky.max@foxmail.com>
     * Date: 22/11/22
     *
     * @return Response
     */
    public function addAddr(): Response
    {
        //
        $param = Request::post();
        $this->addr->addAddr($param);

        return static::parseToData([], 1, '添加成功');
    }

    /**
     * 地址列表
     * Author: 亓官雨树 <lucky.max@foxmail.com>
     * Date: 22/11/22
     *
     * @return Response
     */
    public function addrList(): Response
    {
        $data = $this->addr->addrList();

        return static::parseToData($data, 1, '获取成功');
    }

    /**
     * 修改地址
     * Author: 亓官雨树 <lucky.max@foxmail.com>
     * Date: 22/11/22
     *
     * @return Response
     */
    public function updateAddr(): Response
    {
        $param = Request::put();
        $this->addr->updateAddr($param);

        return static::parseToData([], 1, '修改成功');
    }

    /**
     * 设置默认
     * Author: 亓官雨树 <lucky.max@foxmail.com>
     * Date: 22/11/22
     *
     * @return Response
     */
    public function setDefault(): Response
    {
        $id  = Request::put('id/d');
        $val = Request::put('default/d') ?: 0;
        $this->addr->setDefault($id, $val);

        return static::parseToData([], 1, '设置成功');
    }

    /**
     * 删除地址
     * Author: 亓官雨树 <lucky.max@foxmail.com>
     * Date: 22/11/22
     *
     * @return Response
     */
    public function delAddr(): Response
    {
        $id = Request::delete('id/d');
        $this->addr->delAddr($id);

        return static::parseToData([], 1, '删除成功');
    }

}
